package com.shr.code_interview;

import java.util.ArrayList;
import java.util.LinkedList;
import java.util.Queue;

public class Solution_32 {
    public ArrayList<Integer> PrintFromTopToBottom(TreeNode root) {
    	ArrayList<Integer> array = new ArrayList<>();
    	if(root != null){
	    	Queue<TreeNode> queue = new LinkedList<>();
	    	queue.add(root);
	    	while(!queue.isEmpty()){
	    		TreeNode treeNode = queue.poll();
	    		array.add(treeNode.val) ;
	    		if(treeNode.left != null)
	    			queue.add(treeNode.left) ;
	    		if(treeNode.right != null)
	    			queue.add(treeNode.right) ;
	    	}
    	}
    	return array ;
    }
}
